package com.ruoyi.project.shop.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.shop.domain.LitemallGoods;
import com.ruoyi.project.shop.service.ILitemallGoodsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品基本信息Controller
 *
 * @author ruoyi
 * @date 2020-03-11
 */
@RestController
@RequestMapping("/shop/goods")
public class LitemallGoodsController extends BaseController
{
    @Autowired
    private ILitemallGoodsService litemallGoodsService;

    /**
     * 查询商品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('shop:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(LitemallGoods litemallGoods)
    {
        startPage();
        List<LitemallGoods> list = litemallGoodsService.selectLitemallGoodsList(litemallGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('shop:goods:export')")
    @Log(title = "商品基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LitemallGoods litemallGoods)
    {
        List<LitemallGoods> list = litemallGoodsService.selectLitemallGoodsList(litemallGoods);
        ExcelUtil<LitemallGoods> util = new ExcelUtil<LitemallGoods>(LitemallGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 获取商品基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(litemallGoodsService.selectLitemallGoodsById(id));
    }

    /**
     * 新增商品基本信息
     */
    @PreAuthorize("@ss.hasPermi('shop:goods:add')")
    @Log(title = "商品基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LitemallGoods litemallGoods)
    {
        return toAjax(litemallGoodsService.insertLitemallGoods(litemallGoods));
    }

    /**
     * 修改商品基本信息
     */
    @PreAuthorize("@ss.hasPermi('shop:goods:edit')")
    @Log(title = "商品基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LitemallGoods litemallGoods)
    {
        return toAjax(litemallGoodsService.updateLitemallGoods(litemallGoods));
    }

    /**
     * 删除商品基本信息
     */
    @PreAuthorize("@ss.hasPermi('shop:goods:remove')")
    @Log(title = "商品基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(litemallGoodsService.deleteLitemallGoodsByIds(ids));
    }
}
